package com.ftg.learn.util;

import lombok.Data;

import java.util.Collections;

/**
 * @author Guo
 * @date 2022/3/7
 */
@Data
public class ResEntity {

    private int code;

    private String msg;

    private Object data;

    public ResEntity() {

    }

    public ResEntity(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public ResEntity OK(String msg, Object data) {
        return new ResEntity(0, msg, Collections.emptyMap());
    }

    public ResEntity OK() {
        return new ResEntity(0, "success", Collections.emptyMap());
    }

    public ResEntity OK(Object data) {
        return new ResEntity(0, "success", data);
    }

    public ResEntity Failure(String msg, Object data) {
        return new ResEntity(-1, msg, data);
    }

    public ResEntity Failure() {
        return new ResEntity(-1, "failure", Collections.emptyMap());
    }

    public static ResEntity loginOk(Object data) {
        return new ResEntity(0, "success", data);
    }

    public static ResEntity LoginFailure(String msg) {
        return new ResEntity(-9, msg, Collections.emptyMap());
    }

    /**
     * @param msg 失败信息
     * @return ResEntiy
     */
    public ResEntity Failure(String msg) {
        return new ResEntity(-1, msg, Collections.emptyMap());
    }

}
